<?php
if ((isset($_GET['action'])) && ($_GET['action'] == "save")){
	$admin_ids = $_POST['admin_ids'];
	mysql_query("UPDATE `players` SET `admin`=0") or die(mysql_error());
	for ($i=0;$i< count($admin_ids);$i++){
	mysql_query("UPDATE `players` SET `admin`=1 WHERE `id`={$admin_ids[$i]}") or 
	die(mysql_error());}
	}
?>
<h2>Управление пользователями</h2>

<form action="index.php?section=admin&mode=users&action=save" method="post">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
 <tr bgcolor="#000000"> 
  <td width="100%"> 
   <table border="0" width="100%">
    <tr bgcolor="#222222"> 
	<td valign="bottom" colspan="2" > 
	ID
	</td>
	<td valign="bottom" colspan="2" > 
	Login
	</td>
	<td valign="bottom" colspan="2" > 
	Имя
	</td>
	<td valign="bottom" colspan="2" > 
	Фамилия
	</td>
	<td valign="bottom" colspan="2" > 
	E-Mail
	</td>
	<td valign="bottom" colspan="2" > 
	Команда
	</td>
	<td valign="bottom" colspan="2" > 
	Админ
	</td>
	</tr>
	<?php
	$sqlindex = mysql_query("SELECT * FROM `players`;");
	for ($i = 0; $i < mysql_num_rows($sqlindex); $i++)
	{
		$sqlplayerarray = mysql_fetch_assoc ($sqlindex);
		
		if ($sqlplayerarray['admin']) {
			$team = "<i><b>admin</b></i>";
			$admin = "<input type='checkbox' name='admin_ids[ ]' value={$sqlplayerarray['id']} 
								checked='checked'>";
			} else {
			$admin = "<input type='checkbox' name='admin_ids[ ]' value={$sqlplayerarray['id']}>";
			if ($sqlplayerarray['team_id']) {
				$teamarray=mysql_fetch_assoc(mysql_query("SELECT `team` FROM 
				`teams` WHERE `id` = {$sqlplayerarray['team_id']} LIMIT 1"));
				$team = $teamarray['team'];
				} else $team = "<i>не выбрана</i>";
			
		}
		
		
		print "
    <tr bgcolor=\"#333333\"> 
	<td valign=\"bottom\" colspan=\"2\" > 
	{$sqlplayerarray['id']}
	</td>
	<td valign=\"bottom\" colspan=\"2\" > 
	{$sqlplayerarray['login']}
	</td>
	<td valign=\"bottom\" colspan=\"2\" > 
	{$sqlplayerarray['fname']}
	</td>
	<td valign=\"bottom\" colspan=\"2\" > 
	{$sqlplayerarray['sname']}
	</td>
	<td valign=\"bottom\" colspan=\"2\" > 
	{$sqlplayerarray['email']}
	</td>
	<td valign=\"bottom\" colspan=\"2\" > 
	{$team}
	</td>
	<td valign=\"bottom\" colspan=\"2\" > 
	{$admin}
	</td>
	</tr>";
	}
	?>
	</table>
	</td>
	</tr>
	</table><br />
	<input type="submit" value="Сохранить">
	<input type="reset" value="Отменить">
	</form>